//--------------------------切换两个盒子--------------------
//点击登录的盒子里面的a标签,让注册的盒子显示
$('.login a').on('click', function () {
  $('.register').show();
})
//点击去注册盒子里面的a标签,让去注册的盒子隐藏
$('.register a').on('click', function () {
  $('.register').hide()
})



//-----------登录功能-------------------
$('.login form').on('submit', function (e) {
  e.preventDefault();
  let data = $(this).serialize();
  axios.post('/api/login', data).then(function (res) {
    let { status, message, token } = res.data;
    if (status === 0) {
      localStorage.setItem('token', token);
      layer.msg(message, { time: 1500 }, () => {
        location.href = './index.html'
      });

    }
  })
})





//-----------------------------注册功能----------------------------

$('.register form').on('submit', function (e) {
  e.preventDefault();
  let data = $(this).serialize();
  axios.post('/api/reguser', data).then(res => {
    let { status, message } = res.data;
    if (status === 0) {
      layer.msg(message);
      $('.register form')[0].reset();
      $('.register').hide()
    }

  })
})



//-----------------------------表单验证----------------------------
let form = layui.form;
form.verify({
  len: [/^\S{6,12}$/, '长度6~12位且不能有空格'],
  same: function (val) {
    let pwd = $('.pwd').val();
    if (pwd !== val) return '两次密码不一致';
  }
});

/* let form=layui.form;
form.verify({
  len:[/^\S{6,12}$/,'长度6~12且不能有空格'],
  same:function (val) {
    let pwd=$('.pew').val();
    if(pwd!==val) return '两次密码不一致';
  }
}) */